import JWTToken from './../../helpers/jwt'

export default{
    actions:{
        loginRequest({dispatch},formData){
            return axios.post('/api/login',formData).then(response=>{
                dispatch('loginSuccess',response.data)
            })
        },
        loginSuccess({dispatch},tokenResponse){
            JWTToken.setToken(tokenResponse.token)
            JWTToken.setAuthId(tokenResponse.auth_id)//把加密后的refresh_token存入js-cookie
                dispatch('setAuthUser')
        },
        logoutRequest({dispatch}){
            return axios.post('/api/logout').then(response=>{
                JWTToken.removeToken()
                dispatch('unsetAuthUser')
            })
           
        }
    } 
}